/*
 * Niiuzu
 * Copyright (C) 2011  Thierry Nowak
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.niiuzu.client.screen.feed.viewer;

import java.util.Date;

import com.mvp4g.client.annotation.Presenter;
import com.mvp4g.client.presenter.LazyPresenter;
import com.niiuzu.client.eventbus.FeedEventBus;
import com.niiuzu.shared.model.RssEntry;

/**
 * Presenter dédié à la consultation des données provenant des flux RSS.
 */
@Presenter(view = FeedViewerViewImpl.class)
public class FeedViewerPresenter extends
		LazyPresenter<FeedViewerView, FeedEventBus> {

	/**
	 * La consultation des données provenant des flux RSS est en cours de
	 * chargement.
	 * 
	 * @see FeedEventBus#feedViewerLoadStarted()
	 */
	public void onFeedViewerLoadStarted() {
		eventBus.feedViewerLoaded(view);
	}

	/**
	 * Réception de nouvelles données provenant de flux RSS.
	 * 
	 * @see FeedEventBus#feedEntriesReceived(RssEntry[])
	 */
	public void onFeedEntriesReceived(RssEntry[] feedEntries) {
		view.clearAllFeedData();
		for (RssEntry entry : feedEntries) {

			String link = entry.getLink();
			Date date = entry.getDate();
			String summary = entry.getSummary();

			view.addFeedEntry(link, date, summary);
		}
	}
}
